{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "source": [
    "from torchvision import transforms as T\r\n",
    "import matplotlib.pyplot as plt\r\n",
    "from torchvision.datasets import ImageFolder\r\n",
    "\r\n",
    "\r\n",
    "dataset = ImageFolder('data/dogcat_2/')\r\n",
    "\r\n",
    "# cat文件夹的图片对应label 0，dog对应1\r\n",
    "print(dataset.class_to_idx)\r\n",
    "\r\n",
    "# 所有图片的路径和对应的label\r\n",
    "print(dataset.imgs)\r\n",
    "\r\n",
    "# 没有任何的transform，所以返回的还是PIL Image对象\r\n",
    "#print(dataset[0][1])# 第一维是第几张图，第二维为1返回label\r\n",
    "#print(dataset[0][0]) # 为0返回图片数据\r\n",
    "plt.imshow(dataset[0][0])\r\n",
    "plt.axis('off')\r\n",
    "plt.show()"
   ],
   "outputs": [],
   "metadata": {}
  }
 ],
 "metadata": {
  "orig_nbformat": 4,
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}